use "$OUTDATA/ddd-reds_withmain.dta", clear // load reds main data


rename yearbirth yearb
gen hindu1 = (muslim == 0)
gen christian = relig == 4
replace hindu = relig == 1

rename post dow_cohort

rename dow99 dow_99
sum dow_99,d
drop if dow_99>=r(p99) & dow_99!=.
gen missingdow = dow_99 == .
// Karnataka and Maharashtra had issues with missing dowry data (see appendix of Chiplunkar and Weaver)
// In Maharashtra surveyors correctly recorded if dowry was not paid (value of zero), but in nearly all cases where it was paid, they did not record the value. As a result, they recorded a missing value for the dowry payment field in that situation.
// In Karnataka cases where the respondents did not pay dowry were recorded as missing values.

replace missingdow = . if state == 10 | state == 7

sort year_marriage

replace dow_99 = dow_99/1000
replace downet_99 = downet_99/1000

drop _merge
// merge with deflate data
merge m:1 year_marriage using "$OUTDATA/deflatedow"

rename year_marriage yy_1marr
keep if yy_1marr >= 1975

gen dowTreat = dow_cohort*hindu1

gen yearb1975 = (yearb<1975)
replace  yearb1975 =. if yearb == .

// zero dowry dummy
gen zdow=dow_99==0
replace zdow=. if dow_99==.
replace zdow = . if state == 7

gen scstbc = (caste_sc == 1 | caste_st == 1 | caste_obc == 1)
gen rural = 1
label var dow_cohort "Post"
label var hindu1 "Non-Muslim"


gen marr_age = yy_1m - yearb
gen age = 1999 - yearb



// main wife deck
gen dow_mainwife = dow_99 if deck8==1
replace dow_mainwife = . if deck8==.

* Labels

label var dow_99 "Dowry"
label var downet_99 "Net Dowry"
label var zdow "No Dowry"

label var scstbc "SC/ST/OBC"
label var rural "Rural"
label var muslim "Muslim"
label var christian "Christian"
label var hindu "Hindu"
label var primary "Primary School"
label var secondary "Secondary School"  
label var primary_spouse "Husband Primary School"
label var secondary_spouse "Husband Secondary School"
label var years_schooling "Years of Schooling"
label var years_schooling_spouse "Husband Years of Schooling"
label var owns_land "Land Ownership"  
label var hh_members "Household Size"  
label var marr_age "Age at Marriage"  

********************************************************************************

keep if deck8==1 // only main wife age and education diff


gen agegap = agehus - agewife //age gap
sum agegap,d
replace agegap = . if agegap<-1 | agegap>r(p99)

gen educgap = years_schooling_spouse - years_schooling //education gap
sum educgap,d
replace educgap = . if educgap<r(p1)


gen logdist = log(1 + distsp) // distance to natal home
sum logdist,d
replace logdist = . if logdist>r(p99)

gen wealth_gap = nhuswealth-nwifewealth
sum wealth_gap,d
replace wealth_gap = . if wealth_gap<r(p1) | wealth_gap>r(p99)

gen land_gap = loglandh - loglandw
sum land_gap,d
replace land_gap = . if land_gap<r(p1) | land_gap>r(p99)

gen father_educ_gap = educfh- educfw

sum father_educ_gap,d
replace father_educ_gap = . if father_educ_gap<r(p1) | father_educ_gap>r(p99)

g redsmainwife = 1

save "$OUTDATA/mainwifeonly",replace

